package com.activenetwork.util.jaxb;

import java.io.IOException;
import java.io.InputStream;

import com.google.common.io.Resources;

public class XMLBindHelper {
	
	private InputStream inputStream;
	
	public XMLBindHelper(InputStream inputStream){
		this.inputStream = inputStream;
	}
	
	public XMLBindHelper(String resource) throws IOException{
		inputStream = Resources.getResource(resource).openStream();
	}
	
	/**
	 * Binding the xml with schema object
	 * @param <T>
	 * @param xmlRootNodeType
	 * @return
	 */
	public <T extends Object> T binding(Class<T> xmlRootNodeType){
		String bindingClassPath = xmlRootNodeType.getPackage().getName();
		return JaxbBindUtil.buildObject(inputStream, bindingClassPath, xmlRootNodeType);
	}
	
}
